//
//  TZSettingVc.m
//  BSBDJ
//
//  Created by user on 16/5/25.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZSettingVc.h"
#import "FileManagerTool.h"


@interface TZSettingVc ()

@property (nonatomic, strong) NSIndexPath *indexpath;

@property (nonatomic, strong) TZRowModel *deleteRow;

@property (nonatomic, weak) UITableViewCell *deletecell;

@end

@implementation TZSettingVc

- (instancetype)init{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self addGroup0];
    [self addGroup1];
}

- (void)addGroup0{
    //组
    TZGroupModel *group = [TZGroupModel new];
    group.headerTitle = @"功能设置";
    //行
    TZRowModel *row1 = [TZRowModel rowmodelWithIcon:nil name:@"字体大小"];
    row1.block = ^(){
       
        [SVProgressHUD showSuccessWithStatus:@"好了"];
    };
    TZRowModel *row2 = [TZRowModel rowmodelWithIcon:nil name:@"转发时收藏"];
    row2.block = ^(){
        [SVProgressHUD showSuccessWithStatus:@"好了好了好"];
    };
    TZRowModel *row3 = [TZSwitchModel rowmodelWithIcon:nil name:@"夜间模式"];
    
    group.items = @[row1,row2,row3];
    [self.groups addObject:group];
}

#warning 刷新没有反应 重新进去页面有反应

- (void)addGroup1{
   
    MJWeakSelf
    //组
    TZGroupModel *group = [TZGroupModel new];
    group.headerTitle = @"其他";
    //行
    TZRowModel *row1 = [TZRowPushModel rowmodelWithIcon:nil name:@"离线下载"];
    TZRowModel *row2 = [TZRowPushModel rowmodelWithIcon:nil name:@"推荐朋友"];
    
    TZRowModel *row3 = [TZRowModel rowmodelWithIcon:nil name:[FileManagerTool getCachesFileSize]];
    row3.block = ^{
        NSIndexPath *indexpath = self.tableView.indexPathForSelectedRow;
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexpath];
        [SVProgressHUD showSuccessWithStatus:@"清空缓存"];
        cell.textLabel.text = @"清理缓存:(0.0b)";
        [FileManagerTool removeDirectoryPath:cachePath];
    };
    
    TZRowModel *row4 = [TZRowPushModel rowmodelWithIcon:nil name:@"帮助"];
    TZRowModel *row5 = [TZRowPushModel rowmodelWithIcon:nil name:@"当前版本"];
    TZRowModel *row6 = [TZRowPushModel rowmodelWithIcon:nil name:@"关于我们"];
    TZRowModel *row7 = [TZRowPushModel rowmodelWithIcon:nil name:@"设备信息"];
    TZRowModel *row8 = [TZRowPushModel rowmodelWithIcon:nil name:@"隐私政策"];
    TZRowModel *row9 = [TZRowPushModel
                        rowmodelWithIcon:nil name:@"打分支持不得姐!"];
    
    
    group.items = @[row1,row2,row3,row4,row5,row6,row7,row8,row9];
    [self.groups addObject:group];
}

- (void)setupUI{
    self.view.backgroundColor = XMGColor(244, 244, 244);
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  
    TZGroupModel *groupModel = self.groups[indexPath.section];
    TZRowModel *rowModel = groupModel.items[indexPath.row];
    if ([rowModel isKindOfClass:[TZRowModel class]]) {
        rowModel  = (TZRowModel *)rowModel;
        if (rowModel.block) {
            rowModel.block();
        }
    }

}


/*
 cell.textLabel.text = ;
 if (indexPath.section == 0) {
 [SVProgressHUD showSuccessWithStatus:@"清理成功"];
 ;
 [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
 }*/

@end
